package start;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import util.ByteBuffer;

/**
 * @author Administrator
 * 
 */
public class ClientStart2
{
	public static int num;
	public static Socket socket;

	public static long time;

	public static void main(String[] args)
	{

		startConnector();
		while(true)
		{
			if(System.currentTimeMillis() > time )
			{
				time = System.currentTimeMillis() + 100;
				sendMessage();
//				System.err.println("执行message");
			}
		}
	}

	private static void sendMessage()
	{
		OutputStream out;
		try
		{
			out = socket.getOutputStream();
			ByteBuffer data = new ByteBuffer();
			data.writeInt(999);
			data.writeInt(1);
			data.writeInt(1234);
			ByteBuffer data2 = new ByteBuffer();
			
			System.err.println(data.getEffective());
			
			data2.writeInt(data.getEffective());
			data2.writeBytes(data.getBytes(),0,data.getEffective());
			
			out.write(data2.getBytes(), 0, data2.getEffective());
			out.flush();
			System.err.println("......................."+num++);
			InputStream in = socket.getInputStream();
			
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		
	
	}

	private static void startConnector()
	{
		try
		{
			socket = new Socket("0.0.0.0", 9003);
//			socket.setTcpNoDelay(true);
			
		} catch (IOException e)
		{
			e.printStackTrace();
		}

	}
}
